package com.hc.music.controller;

import com.hc.music.common.R;
import com.hc.music.entity.Comment;
import com.hc.music.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @RequestMapping("insert")
    public R insert(@RequestBody Comment comment){
        comment.setCreateTime(new Date(System.currentTimeMillis()));
        comment.setUp(0);
        return commentService.addComment(comment);
    }

    @RequestMapping("praise")
    public R star(@RequestBody Comment comment){
        return commentService.updateCommentMsg(comment);
    }

    @RequestMapping("delete")
    public R delete(@RequestParam Integer id){
        return commentService.deleteComment(id);
    }

    @RequestMapping("selectBySongId")
    public R selectBySongId(@RequestParam Integer songId){
        return commentService.commentOfSongId(songId);
    }

    @RequestMapping("selectBySongListId")
    public R selectBySongListId(@RequestParam Integer songListId){
        return commentService.commentOfSongListId(songListId);
    }
}
